<template>
  <div>
    <div class="title">实物调整审核</div>
    <base-list ref="auditMatter"
               :condition="condition"
               :datas.sync="auditMatterData"
               :pageSearch="pageSearch">
      <el-form :inline="true"
               :model="condition"
               class="search-form"
               slot="search"
               ref="aList"
               label-width="80px">
        <el-row>
          <el-col :span="6"
                  class="search-width6">
            <el-form-item label="审核状态">
              <el-select v-model="condition['search_EQ_status']"
                         placeholder="请选择"
                         clearable
                         filterable>
                <el-option v-for="[key, val] in _dictAdjustStatus"
                           :key="key"
                           :label="val"
                           :value="key"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6"
                  class="search-width6">
            <el-form-item label="申请类型">
              <el-select v-model="condition['search_EQ_adjustWay']"
                         placeholder="请选择"
                         clearable
                         filterable>
                <el-option v-for="[key, val] in _dictAdjustWay"
                           :key="key"
                           :label="val"
                           :value="key"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6"
                  class="search-width6">
            <el-form-item label="跟踪号">
              <el-input type="text"
                        v-model="condition['search_LIKE_barcode']"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="3"
                  style="width: 190px;">
            <el-button type="primary"
                       icon="el-icon-search"
                       @click="loadData"
                       class="ml-80">查 询</el-button>
            <el-button formVisible="true"
                       icon="el-icon-refresh"
                       @click="resuleBtn('aList')">
              重置
            </el-button>
          </el-col>
        </el-row>
      </el-form>
      <el-table slot="list"
                :data="auditMatterData"
                border
                max-height="550">
        <el-table-column type="expand"
                         width="60">
          <template slot-scope="props">
            <el-form label-position="left"
                     inline
                     class="demo-table-expand">
              <el-col class="table-expand-style">
                <el-form-item label="原件数">
                  <span>{{ props.row.inventoryNum}}</span>
                </el-form-item>
              </el-col>
              <el-col class="table-expand-style">
                <el-form-item label="新件数">
                  <span>{{ props.row.num}}</span>
                </el-form-item>
              </el-col>
              <el-col class="table-expand-style">
                <el-form-item label="原重量">
                  <span>{{ props.row.inventoryWeight}}</span>
                </el-form-item>
              </el-col>
              <el-col class="table-expand-style">
                <el-form-item label="新重量">
                  <span>{{ props.row.newWeight}}</span>
                </el-form-item>
              </el-col>
              <el-col class="table-expand-style">
                <el-form-item label="原数量">
                  <span>{{ props.row.inventoryCountNum}}</span>
                </el-form-item>
              </el-col>
              <el-col class="table-expand-style">
                <el-form-item label="新数量">
                  <span>{{ props.row.newCountNum}}</span>
                </el-form-item>
              </el-col>
              <el-col class="table-expand-style">
                <el-form-item label="调整件数">
                  <span>{{ props.row.num}}</span>
                </el-form-item>
              </el-col>
              <el-col class="table-expand-style">
                <el-form-item label="调整重量">
                  <span>{{ props.row.weight}}</span>
                </el-form-item>
              </el-col>
              <el-col class="table-expand-style">
                <el-form-item label="调整数量">
                  <span>{{ props.row.countNum}}</span>
                </el-form-item>
              </el-col>
              <el-col class="table-expand-style">
                <el-form-item label="原库位">
                  <span>{{ props.row.oldRoomLocation}}</span>
                </el-form-item>
              </el-col>
              <el-col class="table-expand-style">
                <el-form-item label="新库位">
                  <span>{{ props.row.roomLocation}}</span>
                </el-form-item>
              </el-col>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column label="序号"
                         type="index"
                         width="50"></el-table-column>
        <el-table-column prop="adjustWay"
                         label="申请类型"
                         min-width="80">
          <template slot-scope='scope'>
            {{scope.row.adjustWay | _filterAdjustWay }}
          </template>
        </el-table-column>
        <el-table-column prop="status"
                         label="审核状态"
                         _filterAdjustStatus
                         min-width="120">
          <template slot-scope='scope'>
            {{scope.row.status | _filterAdjustStatus }}
          </template>
        </el-table-column>
        <el-table-column prop="manageWay"
                         label="管理方式"
                         min-width="100">
          <template slot-scope='scope'>
            {{scope.row.manageWay | _filterManagement }}
          </template>
        </el-table-column>
        <el-table-column prop="inventoryId"
                         label="物资ID"
                         min-width="60"></el-table-column>
        <el-table-column prop="trackingNo"
                         label="跟踪号"
                         min-width="80"></el-table-column>
        <el-table-column prop="baleNo"
                         label="捆包号"
                         min-width="80"></el-table-column>
        <el-table-column prop="stoveNo"
                         label="炉批号"
                         min-width="80"></el-table-column>
        <el-table-column prop="normStr"
                         label="规格"
                         min-width="80"></el-table-column>
        <el-table-column prop="madeBy"
                         label="产地"
                         min-width="80"></el-table-column>
        <el-table-column prop="material"
                         label="材质"
                         min-width="80"></el-table-column>
        <el-table-column prop="measureWay"
                         label="计量方式"
                         min-width="80">
          <template slot-scope='scope'>
            {{scope.row.measureWay | _filterMeterStyle }}
          </template>
        </el-table-column>
        <el-table-column prop="transhipNo"
                         label="车船号"
                         min-width="80"></el-table-column>
        <el-table-column align="center"
                         label="操作"
                         width="240">
          <template slot-scope="scope">
            <el-button size="small"
                       type="text"
                       :disabled="scope.row.status==='B'|| scope.row.status==='C'"
                       @click="handleDialogForm(true,scope.row)">
              编辑
            </el-button>
            <el-button type="text"
                       class="danger"
                       size="small"
                       :disabled="scope.row.status==='B' || scope.row.status==='C'"
                       @click="handleRemove(scope.row)">删除
            </el-button>
            <el-button size="small"
                       type="text"
                       :disabled="scope.row.status==='B' || scope.row.status==='C' || scope.row.status==='C'"
                       @click="submit(scope.row)">
              提交
            </el-button>
            <el-button size="small"
                       type="text"
                       :disabled="scope.row.status==='A' || scope.row.status==='C' || scope.row.status==='D'"
                       @click="auditPass(scope.row)">
              审核
            </el-button>
            <el-button size="small"
                       type="text"
                       :disabled="scope.row.status==='A' || scope.row.status==='C' || scope.row.status==='D'"
                       @click="auditFailed(scope.row)">
              退回
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </base-list>
    <div style="text-align:center">
      <el-button plain
                 type="info"
                 plain
                 @click="handleRouterPush({path: '/goods/matter',name: '实物管理工作台'})">返回</el-button>
    </div>
    <adjust-stock-form ref="adjustStockForm"
                       @load="loadData"></adjust-stock-form>
  </div>
</template>

<script>
import {
  getAuditMatterList,
  deleteAuditMatter,
  submitAuditMatter,
  auditPass,
  auditFailed
} from '@/api/matter/auditMatter'
import adjustStockForm from './adjustStockForm'

export default {
  name: 'auditMatter',
  components: {
    adjustStockForm
  },
  data() {
    return {
      form: this.clearForm(),
      dialogForm: false,
      component: '',
      condition: {}, // 查询条件
      auditMatterData: [], // table数组
      pmLIst: [], //接口获取的货物属性数据
      warehouseList: [],
      pageSearch: getAuditMatterList // 分页查询api接口
    }
  },
  mounted() {
     getAuditMatterList().then(res => {
      console.log(res.data.aaData)
    })
    this.$nextTick(() => {
      this.loadData()
    })
  },
  methods: {
    clearForm() {
      return {}
    },
    loadData() {
      this.$refs.auditMatter.loadData()
    },
    //编辑
    handleDialogForm(bool, item) {
      if (bool) {
        this.$refs.adjustStockForm.form = JSON.parse(JSON.stringify(item))
        this.$refs.adjustStockForm.isEdit = true
        this.$refs.adjustStockForm.dialogForm = true
      }
    },
    //删除
    handleRemove(item) {
      this.$confirm(`是否删除该数据?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          deleteAuditMatter(item.id).then(res => {
            this.$message({
              type: 'success',
              message: `删除成功!`
            })
            this.loadData()
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    // 提交
    submit(item) {
      this.$confirm('确认提交所选中的调整信息吗？', '确认提交', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          submitAuditMatter(item.id).then(res => {
            this.$message({
              type: 'success',
              message: '提交成功!'
            })
            this.loadData()
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消提交'
          })
        })
    },
    //审核通过
    auditPass(item) {
      this.$confirm(`确定审核通过吗?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          auditPass(item.id).then(res => {
            this.$message({ type: 'success', message: '审核通过' })
            this.dialogForm = false
            this.loadData()
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    //审核不通过
    auditFailed(item) {
      this.$prompt('请输入不通过的原因', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      })
        .then(({ value }) => {
          this.reason = value
          auditFailed(item.id, { reason: value }).then(res => {
            this.form.reason = value
            this.$message({ type: 'warning', message: '审核不通过' })
            this.dialogForm = false
            this.loadData()
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '取消输入'
          })
        })
    },
    resuleBtn(aList) {
      this.$refs[aList].resetFields()
      this.condition = this.clearForm()
    },
    handleRouterPush(val) {
      this.$store.commit('ADD_CACHED_VIEWS', val)
      this.$router.push(val.path)
    }
  }
}
</script>

<style>
.control-line {
  height: 30px;
}
.line {
  border-left: solid 5px #00a1ff;
  height: 18px;
  margin-top: 5px;
  display: inline-block;
  vertical-align: sub;
}
.gg-input {
  margin-bottom: 0 !important;
}
.gg-input .el-form-item__content .el-input {
  width: 100px !important;
}
.search-width8 {
  width: 450px;
}
.base-list .search .border-line {
  margin-top: 0px !important;
}
.table-expand-style {
  width: 300px;
}
.table-expand-style label {
  color: #99a9bf;
}
</style>
